{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': '8da2faec159a4a419f9752e361eb3761',\n",
       " 'time_used': 162,\n",
       " 'face_count': 0,\n",
       " 'face_added': 0,\n",
       " 'request_id': '1603519426,3e2e60c0-1e75-4657-80fd-03d033918c4c',\n",
       " 'outer_id': 'zjy_0',\n",
       " 'failure_detail': []}"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#  1.FaceSet Create（创建人脸集合）\n",
    "api_secret = \"dJZK70wqWOpvXYKpdBwXS5PVdZ4u0HMZ\"\n",
    "api_key = 'cYreV8BIHl_BNjOkwJI9_tLujB3TdMF2'  # Replace with a valid Subscription Key here.\n",
    "# 1. FaceSet Create\n",
    "import requests,json\n",
    "\n",
    "display_name = \"人脸集合face_0\"\n",
    "outer_id = \"zjy_0\"\n",
    "user_data = \"相册\"\n",
    "\n",
    "CreateFace_Url = \"https://api-cn.faceplusplus.com/facepp/v3/faceset/create\"\n",
    "payload = {\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'display_name':display_name,\n",
    "    'outer_id':outer_id,\n",
    "    'user_data':user_data\n",
    "}\n",
    "r = requests.post(CreateFace_Url, params=payload)\n",
    "r.json()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': '8da2faec159a4a419f9752e361eb3761',\n",
       " 'tags': '',\n",
       " 'time_used': 99,\n",
       " 'user_data': '相册',\n",
       " 'display_name': '人脸集合face_0',\n",
       " 'face_tokens': [],\n",
       " 'face_count': 0,\n",
       " 'request_id': '1603519464,519044c3-3579-4a0b-8361-2728129b449e',\n",
       " 'outer_id': 'zjy_0'}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 2.FaceSet GetDetail（获取人脸集合信息）\n",
    "GetDetail_Url = \"https://api-cn.faceplusplus.com/facepp/v3/faceset/getdetail\"\n",
    "payload = {\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'outer_id':outer_id,\n",
    "}\n",
    "r = requests.post(GetDetail_Url,params=payload)\n",
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': 'a9b07ee604f744eeecf13c20f15c955c',\n",
       " 'time_used': 452,\n",
       " 'face_count': 1,\n",
       " 'face_added': 1,\n",
       " 'request_id': '1603520114,4687ee9d-01c9-41d9-a831-d8c5d6735ae0',\n",
       " 'outer_id': 'zjy_1024',\n",
       " 'failure_detail': []}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 3.FaceSet AddFace（增加人脸信息）\n",
    "AddFace_url = \" https://api-cn.faceplusplus.com/facepp/v3/faceset/addface\"\n",
    "\n",
    "payload = {\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'faceset_token':'a9b07ee604f744eeecf13c20f15c955c',\n",
    "    'face_tokens':'e20d625f29c97c64833ed2e31ea9f7ea',\n",
    "}\n",
    "r = requests.post(AddFace_url,params=payload)\n",
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': 'a9b07ee604f744eeecf13c20f15c955c',\n",
       " 'face_removed': 1,\n",
       " 'time_used': 213,\n",
       " 'face_count': 0,\n",
       " 'request_id': '1603520256,724b286a-a002-4a28-8662-6c548318b1dc',\n",
       " 'outer_id': 'zjy_1024',\n",
       " 'failure_detail': []}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 4.FaceSet RemoveFace（移除人脸信息）\n",
    "RemoveFace_url = \" https://api-cn.faceplusplus.com/facepp/v3/faceset/removeface\"\n",
    "\n",
    "payload = {\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'faceset_token':'a9b07ee604f744eeecf13c20f15c955c',\n",
    "    'face_tokens':'e20d625f29c97c64833ed2e31ea9f7ea',\n",
    "}\n",
    "r = requests.post(RemoveFace_url,params=payload)\n",
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': 'a9b07ee604f744eeecf13c20f15c955c',\n",
       " 'request_id': '1603520278,6943710f-5327-483a-ae9b-4a778384b25c',\n",
       " 'time_used': 63,\n",
       " 'outer_id': 'zjy_1024'}"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 5.FaceSet Update（更新人脸集合信息）\n",
    "Update_url = \"https://api-cn.faceplusplus.com/facepp/v3/faceset/update\"\n",
    "payload = {\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'faceset_token':'a9b07ee604f744eeecf13c20f15c955c',\n",
    "    'user_data':\"Test.\",\n",
    "}\n",
    "r = requests.post(Update_url,params=payload)\n",
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faces1': [{'face_rectangle': {'width': 824,\n",
       "    'top': 871,\n",
       "    'left': 1114,\n",
       "    'height': 824},\n",
       "   'face_token': 'b3c9e5b3b9adb458c112b72b602f9328'}],\n",
       " 'faces2': [{'face_rectangle': {'width': 86,\n",
       "    'top': 91,\n",
       "    'left': 65,\n",
       "    'height': 86},\n",
       "   'face_token': '969961ea68751de87335e2d2ae3c8a9b'}],\n",
       " 'time_used': 2300,\n",
       " 'thresholds': {'1e-3': 62.327, '1e-5': 73.975, '1e-4': 69.101},\n",
       " 'confidence': 26.085,\n",
       " 'image_id2': 'g6kg8zfyOouG6ftP+GvEfg==',\n",
       " 'image_id1': 'KIOXEC2V/MyL4zuopAcNig==',\n",
       " 'request_id': '1603520331,9859209b-b799-49a9-97e3-a70cdccdaeff'}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 6.Compare Face（对比人脸相似度）\n",
    "liudehua01 = \"https://gss0.baidu.com/9fo3dSag_xI4khGko9WTAnF6hhy/zhidao/pic/item/7c1ed21b0ef41bd57f7f20ff57da81cb39db3d89.jpg\"\n",
    "liudehua02 = \"https://tse3-mm.cn.bing.net/th/id/OIP.Xz3HbYZeNrdUnGJ7vXNzsQHaKO?pid=Api&rs=1\"\n",
    "wangzulan = \"https://tse3-mm.cn.bing.net/th/id/OIP.ZnXeGoVYT4jQudiPOGZn3QAAAA?pid=Api&rs=1\"\n",
    "\n",
    "Compare_url = \"https://api-cn.faceplusplus.com/facepp/v3/compare\"\n",
    "payload ={\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'image_url1':liudehua01,\n",
    "    'image_url2':wangzulan\n",
    "}\n",
    "r = requests.post(Compare_url,params=payload)\n",
    "r.json()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
